package Offer2018.java8;

import com.sun.org.apache.bcel.internal.generic.F2D;
import org.junit.Test;

import java.util.Arrays;
import java.util.function.Function;
import java.util.function.IntConsumer;

/**
 * 数组引用
 */
public class ArrayRefTest {

    //Function<T, R>中的R apply(T t)
    //数组的创建           String[Integer l]
    @Test
    public void test1() {
        //普通
        Function<Integer, String[]> f1 = new Function<Integer, String[]>() {
            @Override
            public String[] apply(Integer length) {
                return new String[length];
            }
        };
        String[] a1 = f1.apply(4);
        System.out.println(Arrays.toString(a1));

        //lambda
        Function<Integer, String[]> f2 = length -> new String[length];
        String[] a2 = f2.apply(5);
        System.out.println(Arrays.toString(a2));
        //数组引用
        Function<Integer, String[]> f3 = String[]::new;
        String[] a3 = f3.apply(6);
        System.out.println(Arrays.toString(a3));
    }

}

